/*
** Copyright (c) 2010  Kimmo 'Rainy' Pekkola
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see http://www.gnu.org/licenses.
*/

#include "themedialog.h"
#include "thememanager.h"

//-----------------------------------------------------------------------------
/**
** Constructor
**
** \param pParent The parent for the dialog.
*/
CThemeDialog::CThemeDialog(QWidget* pParent) : QDialog(pParent)
{
    ui.setupUi(this);

    QStringList listThemes = CThemeManager::instance().getThemes();
    listThemes.insert(0, "Default");
    for (int i = 0; i < listThemes.size(); i++)
    {
        QPushButton* pButton = new QPushButton(ui.scrollAreaWidgetContents);
        ui.scrollAreaWidgetContents->setProperty("FingerScrollable", true);
        pButton->setMinimumSize(200, 120);
        pButton->setMaximumSize(200, 120);
        pButton->setIconSize(QSize(200, 120));
        pButton->setFlat(true);

        if (i == 0)
        {
            pButton->setIcon(QIcon(QString(":/screenshot.png")));
        }
        else
        {
            QString strThemePath(":/themes/" + listThemes[i]);
            pButton->setIcon(QIcon(strThemePath + "/screenshot.png"));
        }

        m_ThemeMapper.setMapping(pButton, listThemes[i]);

        bool bOk = connect(pButton, SIGNAL(clicked()), &m_ThemeMapper, SLOT(map()));
        Q_ASSERT(bOk);
        bOk = connect(&m_ThemeMapper, SIGNAL(mapped(const QString &)), this, SLOT(onThemeSelected(const QString &)));
        Q_ASSERT(bOk);

        ui.horizontalLayout->addWidget(pButton);
    }
}

//-----------------------------------------------------------------------------
/**
** Destructor
*/
CThemeDialog::~CThemeDialog()
{
}

//-----------------------------------------------------------------------------
/**
** Slot which is triggered when a theme is selected.
*/
void CThemeDialog::onThemeSelected(const QString& strTheme)
{
    m_SelectedTheme = strTheme;
    done(0);
}

// EOF
